<template>
  <div class="app-container">
    <el-row :gutter="20">
<!--      &lt;!&ndash;部门数据&ndash;&gt;
      <el-col :span="4" :xs="24">
        <div class="head-container">
          <el-input
            v-model="deptName"
            placeholder="请输入部门名称"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 20px"
          />
        </div>
        <div class="head-container">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            default-expand-all
            @node-click="handleNodeClick"
          />
        </div>
      </el-col>-->
      <!--用户数据-->
      <el-col :span="20" :xs="24" style="width: 100%;">
        <el-form :model="queryParams" ref="msgFrom" :inline="true" v-show="true" label-width="68px" prop="msgFrom">
          <el-form-item label="用户名称" prop="name">
            <el-input
              v-model="queryParams.name"
              placeholder="请输入用户名称"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="订阅类型" prop="msg_type">
            <el-select
              v-model="queryParams.msg_type"
              placeholder="订阅类型"
              clearable
              size="small"
              style="width: 240px"
            >
              <el-option
                v-for="dict in msgType"
                :key="dict.id"
                :label="dict.msg_type"
                :value="dict.msg_type"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="订阅时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>


        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="用户编号" align="center" key="user_id" prop="user_id"  />
          <el-table-column label="用户名称" align="center" key="name" prop="name"  :show-overflow-tooltip="true" />
          <el-table-column label="订阅类型" align="center" key="msg_type" prop="msg_type"  :show-overflow-tooltip="true" />
          <el-table-column label="是否订阅" align="center" :show-overflow-tooltip="true" >
            <template slot-scope="scope">
              {{ scope.row.status == 0 ? "取消订阅" : "订阅" }}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" align="center" prop="insert_time"  width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.insert_time) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作时间" align="center" prop="insert_time"  width="160">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.status_modify_time) }}</span>
            </template>
          </el-table-column>

        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getSubscription"
        />
      </el-col>
    </el-row>

    <!-- 添加或修改参数配置对话框 -->
    <!--<el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户昵称" prop="name">
              <el-input v-model="form.name" placeholder="请输入用户昵称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            &lt;!&ndash;<el-form-item label="归属部门" prop="deptId">
              <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
            </el-form-item>&ndash;&gt;
            <el-form-item label="用户生日" prop="deptId">
              <el-input v-model="form.birthday" placeholder="请输入用户生日" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="user_mobile">
              <el-input v-model="form.user_mobile" placeholder="请输入手机号码" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="email">
              <el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item  label="职业" prop="occupation">
              <el-input v-model="form.occupation" placeholder="请输入用户职业" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="用户密码" >
              <el-input v-model="form.user_password" placeholder="请输入用户密码"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="用户性别">
              <el-select v-model="form.sex" placeholder="请选择">
                &lt;!&ndash;<el-option

                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                ></el-option>&ndash;&gt;
                <el-option
                  v-for="item in sexs"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio
                  v-for="item in status"
                  :key="item.id"
                  :label="item.id"
                >{{item.label}}</el-radio>

              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件类型">
              <el-select v-model="form.id_card_type">
                <el-option
                  v-for="item in id_card_type"
                  :key="item.id"
                  :label="item.label"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证件编号">
                <el-input v-model="form.id_card" placeholder="请输入证件编号" type="text" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="用户头像">
              <el-upload class="avatar-uploader"
                         :action="''"
                         :auto-upload="false"
              :show-file-list="false"
              :on-change="handleAvatarChangeIcon">
              <img v-if="user.avator" :src="user.avator" class="avatar" style="height: 150px;">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
              </el-upload>

            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="24">
            <el-form-item label="备注">
              <el-input v-model="form.remarks" type="textarea" placeholder="请输入内容"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>-->


  </div>
</template>

<script>
  import { addUser, updateUser, userSubscription, msgType} from "@/api/system/user";
  import { getToken } from "@/utils/auth";
  import { treeselect } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  export default {
  name: "User",
  components: { Treeselect },
  data() {
    return {
      /*订阅类型*/
      msgType:[],
      /*表格数据*/
      list:[],
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 遮罩层
        loading: true,
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 160,
        name: "",
        subscription:undefined,
        msg_type:undefined
      },
      // 日期范围
      dateRange: [],
    };
  },
  watch: {

  },
  created() {
    this.getSubscription();
    this.getMsgType();
  },

  methods: {

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1;
      this.getSubscription();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm('msgFrom');
      this.handleQuery();
    },


    /*获取订阅列表*/
    getSubscription(){
      this.loading = true;
      userSubscription(this.addDateRange(this.queryParams, this.dateRange)).then(response=>{
        this.list= response.data.items;
        this.total = response.data.total;
        this.loading = false;
      })
    },
    /*获取订阅信息分类表*/
    getMsgType(){
      msgType().then(response =>{
        console.log(response.data);
        this.msgType = response.data.items;
      })
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.user_id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
  },

};
</script>
